package com.redlight.controller;


import com.redlight.base.RestBaseController;
import com.redlight.base.RestResult;
import com.redlight.bean.Employee;
import com.redlight.cache.EhCacheUtils;
import com.redlight.pool.IPoolRunnableTask;
import com.redlight.pool.ThreadPool;
import com.redlight.pool.ThreadPoolFactory;
import com.redlight.service.EmployeePool;
import com.redlight.service.EmployeeService;
import com.redlight.utils.StringUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created by chao on 2019/1/11.
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/api/sys/thread")
public class ThreadController extends RestBaseController {
    @Resource
    private EmployeeService employeeService;

    @Resource
    private ThreadPoolFactory threadPoolFactory;

    @RequestMapping(value = "test",method = RequestMethod.GET)
    public RestResult form() {
        boolean flag = false;
        Object retObject = "操作失败";
        try {
                ThreadPool pool = threadPoolFactory.getPool("redLight");
                for(int i=0;i<=10;i++){
                    IPoolRunnableTask<Map> employeePool=new EmployeePool();
                    Map map=new HashMap();
                    map.put("name","zhangsan");
                    employeePool.init("123",pool,map);
                    pool.excute(employeePool);
                }

                flag = true;
        }catch (Exception e){
            e.printStackTrace();
            retObject = "操作失败:"+e.getMessage();
        }
        return renderResult(flag, flag?Ok:Fail, retObject);
    }


}
